//
//  ChangeNickNameViewController.m
//  MooreDoll
//
//  Created by 郭景豪 on 2014/12/23.
//  Copyright (c) 2014年 Tank. All rights reserved.
//

#import "ChangeNickNameViewController.h"
#import "ConnectStateDelegate.h"
@interface ChangeNickNameViewController ()<ConnectStateDelegate>

@end

@implementation ChangeNickNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.TF_NickName addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
}
- (void)textFieldDidChange:(UITextField *)textField
{
    if (textField == self.TF_NickName) {
        if (textField.text.length > 20) {
            textField.text = [textField.text substringToIndex:20];
        }else
        {
            self.LB_TextLength.text = [NSString stringWithFormat:@"%i/20",textField.text.length];
        }
    }
}
- (IBAction)changeVcardEvent:(id)sender {
    if (self.TF_NickName.text.length>0) {
        
        //將名字還有 圖片路徑包進字典
        NSDictionary *dict = @{@"userImage":[UserInfoModel sharedInstance].ImagePath,@"userName":self.TF_NickName.text};
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            
            while (dict == nil) {
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                
                //這邊註冊了登入後的 delegate
                [XMPPSharedInstance sharedInstance].stateDelegate = self;

                [[XMPPSharedInstance sharedInstance]changeVCard:dict];
            });
            
        });                //執行變更名字和照片
    }
    
}
-(void)getUserImageIsOK:(NSMutableDictionary *)results
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
